package com.august.service.impl;

import com.august.utils.SpringContextUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.*;
import java.util.stream.Collectors;

@Slf4j
public class ProTask implements Runnable {
    private int startIndex;

    private int endIndex;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    private Map<Long, CompanyVo> omsMap;

    private HashMap  hashMap;


    public ProTask(int startIndex,int  endIndex,HashMap  hashMap){
        this.startIndex = startIndex;
        this.endIndex=endIndex;

        this.hashMap = hashMap;

    }
    @Override
    public void run() {
        JdbcTemplate mysql2JdbcTemplate = SpringContextUtil.getBean("mysql2JdbcTemplate");

//        List<Map<String, Object>> listMap = jdbcTemplate.queryForList("select id_uuid,company_number,company_name,province_id,city_id,company_address,"
//                + "post_code,corporation,corporation_tel,manager,manager_tel,contract,contract_tel,web_url "
//                + "from oms_company limit "+startIndex+","+ 2000);

        String sql = "select * from student limit "+startIndex+","+endIndex;
        List<Map<String, Object>> listMap = mysql2JdbcTemplate.queryForList(sql);


        List<HashMap> listHashMap = listMap.stream().map(item -> {

            HashMap hashMap=new HashMap();
            hashMap.put(String.valueOf(item.get("id")),Integer.toString(Objects.hashCode(item)));
            return hashMap;
        }).collect(Collectors.toList());

//        if(null != hashVoList && !hashVoList.isEmpty()){
//
//        }

        listHashMap.forEach((item)->{
           // Object id = item.get("id");
            Iterator it = item.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry entry = (java.util.Map.Entry)it.next();
                String key = (String) entry.getKey();
                String value = (String) entry.getValue();

                String value2 = (String) hashMap.get(key);

                if(!value.equals(value2)){
                    System.out.println("不相同的key为: "+key);
               }
                hashMap.remove(key);
            }

         //   HashVO hashVO = hashMaps.get(item.get("id"));

        });

       // List<CompanyVo> list = CompanyVo.getCompany(listMap);

//        if(null != list && !list.isEmpty()){
//            List<Object[]> obs = new ArrayList<>();
//            for(CompanyVo vo:list){
//                CompanyVo oms = omsMap.get(vo.getIdUuid());
//                if(null == oms){
//                    continue;
//                }
//                if((null == vo.getCompanyNumber() && null != oms.getCompanyNumber())
//                        || (null != vo.getCompanyNumber() && !vo.getCompanyNumber().equals(oms.getCompanyNumber())))
//                {
//                    //结果不同时进行处理
//                }
//                //对已比对数据进行移除
//                omsMap.remove(vo.getIdUuid());
//            }
//        }

    }
}
